|
In computer programming, unreachable code is part of the source code of a program which can never be executed because there exists no control flow path to the code from the rest of the program. Unreachable code is sometimes also called ''dead code'', although dead code may also refer to code that is executed but has no effect on the output of a program. Unreachable code is generally considered undesirable for a number of reasons, including: * Occupies unnecessary memory * Causes unnecessary caching of instructions into the CPU instruction cache - which also decreases data locality. * From the perspective of program maintenance; time and effort may be spent maintaining and documenting a piece of code which is in fact unreachable, hence never executed. ==Causes== The existence of unreachable code can be due to various factors, such as: * programming errors in complex conditional branches; * a consequence of the internal transformations performed by an optimizing compiler; * incomplete testing of a new or modified program that failed to test the bypassed unreachable code; * obsolete code that a programmer forgot to delete; * unused code that a programmer decided not to delete because it was intermingled with functional code; * conditionally useful code that will never be reached, because current input data will never cause that code to be executed; * complex obsolete code that was intentionally retained but made unreachable so that it could be revived later if needed; * debugging constructs and vestigial development code which have yet to be removed from a program. In the latter five cases, code which is currently unreachable is often there as part of a legacy, i.e. code that was once useful but is no longer used or required. However, the unreachable code may also be part of a complex component (library, module or routine), where the code continues to be useful in conjunction with different input data (never generated by the current application) or under conditions which are not met in the current runtime environment, thereby making the corresponding code unreachable, but which can occur in other runtime environments, for which the component has been developed. An example of such a conditionally unreachable code may be the implementation of a printf() function in a compiler's runtime library, which contains complex code to process all possible string arguments, of which only a small subset is actually used in the program. Without recompiling the runtime library, compilers will typically not be able to remove the unused code sections at compile time. 抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)』 ■ウィキペディアで「unreachable code」の詳細全文を読む スポンサード リンク
|